package o;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.util.List;

public class xn implements se<Uri, Drawable> {
    private final Context ˊ;

    public /* synthetic */ boolean ˊ(@NonNull Object obj, @NonNull sc scVar) throws IOException {
        return ˎ((Uri) obj, scVar);
    }

    public xn(Context context) {
        this.ˊ = context.getApplicationContext();
    }

    public boolean ˎ(@NonNull Uri uri, @NonNull sc scVar) {
        return uri.getScheme().equals("android.resource");
    }

    @Nullable
    public tx<Drawable> ˎ(@NonNull Uri uri, int i, int i2, @NonNull sc scVar) {
        Context ˊ = ˊ(uri, uri.getAuthority());
        return xh.ॱ(xj.ˎ(this.ˊ, ˊ, ˋ(ˊ, uri)));
    }

    @NonNull
    private Context ˊ(Uri uri, String str) {
        if (str.equals(this.ˊ.getPackageName())) {
            return this.ˊ;
        }
        try {
            return this.ˊ.createPackageContext(str, 0);
        } catch (Throwable e) {
            if (str.contains(this.ˊ.getPackageName())) {
                return this.ˊ;
            }
            throw new IllegalArgumentException("Failed to obtain context or unrecognized Uri format for: " + uri, e);
        }
    }

    @DrawableRes
    private int ˋ(Context context, Uri uri) {
        List pathSegments = uri.getPathSegments();
        if (pathSegments.size() == 2) {
            return ˎ(context, uri);
        }
        if (pathSegments.size() == 1) {
            return ॱ(uri);
        }
        throw new IllegalArgumentException("Unrecognized Uri format: " + uri);
    }

    @DrawableRes
    private int ˎ(Context context, Uri uri) {
        int identifier;
        List pathSegments = uri.getPathSegments();
        String str = (String) pathSegments.get(0);
        String str2 = (String) pathSegments.get(1);
        int identifier2 = context.getResources().getIdentifier(str2, str, uri.getAuthority());
        if (identifier2 == 0) {
            identifier = Resources.getSystem().getIdentifier(str2, str, "android");
        } else {
            identifier = identifier2;
        }
        if (identifier != 0) {
            return identifier;
        }
        throw new IllegalArgumentException("Failed to find resource id for: " + uri);
    }

    @DrawableRes
    private int ॱ(Uri uri) {
        try {
            return Integer.parseInt((String) uri.getPathSegments().get(0));
        } catch (Throwable e) {
            throw new IllegalArgumentException("Unrecognized Uri format: " + uri, e);
        }
    }
}
